package net.tools.web;

import java.security.*;

import javax.crypto.*;

import org.apache.commons.pool.*;

class KeyedPoolableObjectFactory extends BaseKeyedPoolableObjectFactory
{

	public Object makeObject(Object key) throws Exception
	{
		if(key.equals(ApplicationProcessor.TUNNEL_COMMAND))
			return new TunnelCommand();
		else if(key.equals(ApplicationProcessor.TUNNEL_RESPONSE))
			return new TunnelResponse();
		else if(key.equals(ApplicationProcessor.RSA_CIPHER))
			return Cipher.getInstance("RSA");
		else if(key.equals(ApplicationProcessor.AES_CIPHER))
			return Cipher.getInstance("AES");
		else if(key.equals(ApplicationProcessor.SHA1_MD))
			return MessageDigest.getInstance("SHA1");
		else if(key.equals(ApplicationProcessor.SEC_RAND))
			return new SecureRandom();
		return null;
	}

	public void passivateObject(Object key, Object obj) throws Exception
	{
		if(key.equals(ApplicationProcessor.TUNNEL_COMMAND))
		{
			TunnelCommand cmd = (TunnelCommand) obj;
			cmd.setHost(null);
		}
	}

	/*public boolean validateObject(Object key, Object obj)
	{
		// TODO if(...)
		// TODO for test only, remove this function after test.
		return true;
	}*/

}
